/// 用户注册请求模型
/// 根据MyApplication2和接口文档1.4设计
class UserRegisterRequest {
  final String userPhone;
  final String userCode; // 用户类型：字符串格式 "0"=个人用户，"1"=商家用户
  final String genToken; // 是否生成融云token：字符串格式 "1"=生成，"0"=不生成
  final String? username; // 可选的用户名
  final String? userEmail; // 可选的邮箱
  final String? userAvatarUrl; // 可选的头像URL
  final int? userAge; // 可选的年龄
  final String? userGender; // 可选的性别
  final String? userSignature; // 可选的个性签名
  final List<String>? userTags; // 可选的用户标签
  final String? userCity; // 可选的所在城市
  final String timestamp; // 时间戳

  UserRegisterRequest({
    required this.userPhone,
    required this.userCode,
    this.genToken = "1", // 默认生成token
    this.username,
    this.userEmail,
    this.userAvatarUrl,
    this.userAge,
    this.userGender,
    this.userSignature,
    this.userTags,
    this.userCity,
    required this.timestamp,
  });

  /// 转换为API请求的JSON格式（严格按照MyApplication2格式）
  Map<String, dynamic> toApiJson() {
    final Map<String, dynamic> json = {
      'userPhone': userPhone, // 字符串类型
      'userCode': userCode, // 字符串类型："0"或"1"
      'GenToken': genToken, // 字符串类型："1"或"0"  
      'timestamp': timestamp, // 字符串类型
    };

    // 添加可选字段
    if (username != null) json['username'] = username;
    if (userEmail != null) json['userEmail'] = userEmail;
    if (userAvatarUrl != null) json['userAvatarUrl'] = userAvatarUrl;
    if (userAge != null) json['userAge'] = userAge;
    if (userGender != null) json['userGender'] = userGender;
    if (userSignature != null) json['userSignature'] = userSignature;
    if (userTags != null) json['userTags'] = userTags;
    if (userCity != null) json['userCity'] = userCity;

    return json;
  }

  /// 转换为JSON字符串
  Map<String, dynamic> toJson() => toApiJson();

  @override
  String toString() {
    return 'UserRegisterRequest(userPhone: $userPhone, userCode: $userCode, genToken: $genToken, timestamp: $timestamp)';
  }
}
